package com.hqyj.controller;


import com.hqyj.pojo.TbActivity;
import com.hqyj.pojo.TbComplaint;
import com.hqyj.service.TbActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author gp
 * @since 2021-09-25
 */
@RestController
@RequestMapping("/tb-activity")
public class TbActivityController {

    @Autowired
    TbActivityService tbActivityService;

    /**
     * 新增
     * http://localhost:8080/tb-activity/add
     * {"communityName":"蓝雾苑","communityId":"2","title":"养生会谈","address":"小区茶楼","organizer":"蓝雾苑物业",
     * "createTime":"2021-09-27 11:13:47","updateTime":"2021-09-27 11:13:47","startTime":"2021-09-08 10:30:00","endTime":"2021-09-08 17:30:00","status":"0"
     * }
     *
     * @param tbActivity
     * @return
     */
    @PostMapping(value = "/add", consumes = "application/json")
    public HashMap<String, Object> add(@RequestBody TbActivity tbActivity) {
        return tbActivityService.add(tbActivity);
    }


    /**
     * 修改
     * http://localhost:8080/tb-activity/update
     * {"id":"2","updateTime":"2021-09-27 11:20:47","endTime":"2021-09-08 17:00:00","status":"0"}
     *
     * @param tbActivity
     * @return
     */
    @PutMapping(value = "/update", consumes = "application/json")
    public HashMap<String, Object> update(@RequestBody TbActivity tbActivity) {
        return tbActivityService.update(tbActivity);
    }


    /**
     * 删除
     * http://localhost:8080/tb-activity/del/?
     *
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public HashMap<String, Object> del(@PathVariable Integer id) {
        return tbActivityService.del(id);
    }

    /**
     * 查询
     * http://localhost:8080/tb-activity/list?page=1&row=2
     *
     * @param tbActivity
     * @return
     */
    @GetMapping("/list")
    public HashMap<String, Object> list(TbActivity tbActivity) {
        return tbActivityService.list(tbActivity);
    }

    /**
     * 通过活动标题查询小区活动
     * http://localhost:8080/tb-activity/title/xxx
     *
     * @param title
     * @return
     */
    @GetMapping("/title/{title}")
    public HashMap<String, Object> title(@PathVariable String title) {
        return tbActivityService.tbActivityByTitle(title);
    }
}

